package com.itheima.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
public class JwtUtils {
    private static String sinKey="itheima";
    private static Long expire=43200000L;

    public static String generateJwt(Map<String,Object> claims){
        String jwt=Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256,sinKey)
                .setExpiration(new Date(System.currentTimeMillis()+expire))
                .compact();
        return jwt;
    }

    public static Claims parseJwt(String Jwt){
        Claims claims=Jwts.parser()
                .setSigningKey(sinKey)
                .parseClaimsJws(Jwt)
                .getBody();
        return claims;
    }
}
